﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CatCheater
{
    class Program
    {
        static void Main(string[] args)
        {
            //string[] keys = { "0fafdb808d04803719982c0211f0e1e359c5ad6c20025ba0", 
            //                    "5247bd2df4c3bb1e29368134af18bd03e6f5322ac6f28122" ,
            //                "83a498aedc0c1dbc528beb10b2fbe69a602e372c43b58f42",
            //                "48a63cefe9eb742f59592192905b98811d3a1c8088ec8b90"};
            //string[] finallyKeys = { "a9b2e4ksc0fafdb808d04803719982c0211f0e1e359c5ad6c20025ba0", 
            //                           "chb1ztvf6uf5247bd2df4c3bb1e29368134af18bd03e6f5322ac6f28122",
            //                       "cct26c37taf83a498aedc0c1dbc528beb10b2fbe69a602e372c43b58f42",
            //                       "a1x6ghs6yjd48a63cefe9eb742f59592192905b98811d3a1c8088ec8b90"};
            //string[] scores = { "335", "2285", "2820", "2490" };

            //for (int i = 0; i < keys.Length; i++)
            //{
            //    Console.WriteLine(i);
            //    Console.WriteLine(finallyKeys[i]);
            //    Console.WriteLine(GetFinallyCode(keys[i], scores[i]));
            //    Console.WriteLine("key {0} was right:{1}..", i, GetFinallyCode(keys[i], scores[i]) == finallyKeys[i]);
            //}

            string key = Console.ReadLine();
            string score = Console.ReadLine();

            Console.WriteLine(GetFinallyCode(key, score));
            Console.Read();
        }

        static string GetFinallyCode(string key, string score)
        {
            int iScore = int.Parse(score);
            if (string.IsNullOrEmpty(key) || string.IsNullOrEmpty(score))
            {
                return string.Empty;
            }
            if (key.Length != 48)
            {
                return string.Empty;
            }

            var _loc10 = key;
            key = key.Substring(42, 6);
            AnyRadixConvert converter = new AnyRadixConvert();
            long _loc8 = converter.x2h(key, 36);
            string _loc4 = converter.h2x(_loc8, 35);
            int _loc13 = _loc4.Length;
            long _loc3 = converter.x2h(key.Substring(key.Length - 1), 36) % _loc13;
            string _loc6 = converter.h2x(iScore, 36);
            string _loc12 = _loc4.Substring(0, (int)_loc3);
            string _loc7 = _loc4.Substring((int)_loc3);
            long _loc5 = _loc3 + 10;
            long _loc11 = _loc5 + _loc6.Length;
            string[] _loc9 = { converter.h2x(_loc5, 36), _loc12, _loc6, _loc7, converter.h2x(_loc11, 36), _loc10 };
            return string.Join("", _loc9).ToLower();
        }
    }

    public class AnyRadixConvert
    {
        private static char[] rDigits = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z' };

        /// <summary>
        /// 将指定基数的数字的 System.String 表示形式转换为等效的 64 位有符号整数。
        /// </summary>
        /// <param name="value">包含数字的 System.String。</param>
        /// <param name="fromBase">value 中数字的基数，它必须是[2,36]</param>
        /// <returns>等效于 value 中的数字的 64 位有符号整数。- 或 - 如果 value 为 null，则为零。</returns>
        public long x2h(string value, int fromBase)
        {
            value = value.Trim();
            if (string.IsNullOrEmpty(value))
            {
                return 0L;
            }
            string sDigits = new string(rDigits, 0, fromBase);
            long result = 0;
            //value = reverse(value).ToUpper(); 1
            value = value.ToUpper();// 2
            for (int i = 0; i < value.Length; i++)
            {
                if (!sDigits.Contains(value[i].ToString()))
                {
                    throw new ArgumentException(string.Format("The argument \"{0}\" is not in {1} system.", value[i], fromBase));
                }
                else
                {
                    try
                    {
                        //result += (long)Math.Pow(fromBase, i) * getcharindex(rDigits, value[i]); 1
                        result += (long)Math.Pow(fromBase, i) * getcharindex(rDigits, value[value.Length - i - 1]);//   2
                    }
                    catch
                    {
                        throw new OverflowException("运算溢出.");
                    }
                }
            }
            return result;
        }
        private int getcharindex(char[] arr, char value)
        {
            for (int i = 0; i < arr.Length; i++)
            {
                if (arr[i] == value)
                {
                    return i;
                }
            }
            return 0;
        }

        //long转化为toBase进制
        public string h2x(long value, int toBase)
        {
            int digitIndex = 0;
            long longPositive = Math.Abs(value);
            int radix = toBase;
            char[] outDigits = new char[63];
            for (digitIndex = 0; digitIndex <= 64; digitIndex++)
            {
                if (longPositive == 0) { break; }
                outDigits[outDigits.Length - digitIndex - 1] =
                    rDigits[longPositive % radix];
                longPositive /= radix;
            }
            return new string(outDigits, outDigits.Length - digitIndex, digitIndex);
        }

        //任意进制转换,将fromBase进制表示的value转换为toBase进制
        public string X2X(string value, int fromBase, int toBase)
        {
            if (string.IsNullOrEmpty(value.Trim()))
            {
                return string.Empty;
            }
            if (fromBase < 2 || fromBase > 36)
            {
                throw new ArgumentException(String.Format("The fromBase radix \"{0}\" is not in the range 2..36.", fromBase));
            }
            if (toBase < 2 || toBase > 36)
            {
                throw new ArgumentException(String.Format("The toBase radix \"{0}\" is not in the range 2..36.", toBase));
            }
            long m = x2h(value, fromBase);
            string r = h2x(m, toBase);
            return r;
        }
    }
}